function nFrames = PatFileName(filename_pattern)

FoundFile = 1;
nFrames = 0;
while FoundFile ~= 0
    filename = sprintf(filename_pattern, nFrames+1);
    FoundFile = exist(filename, 'file');
    if FoundFile ~= 0
        nFrames = nFrames+1;
    end
end